package week01

// 66. 加一
// https://leetcode-cn.com/problems/plus-one/

func plusOne(digits []int) []int {
	var add = 1
	for i := len(digits)-1; i >= 0; i-- {
		digits[i] += add
		if digits[i] == 10 {
			digits[i] = 0
			add = 1
		} else {
			add = 0
			break
		}
	}
	if add == 1 {
		return append([]int{1}, digits...)
	}
	return digits
}